<script setup>
import { ref } from 'vue'

const props = defineProps({
  columns: {
    type: Array,
    default: () => [
      { label: '物料名称', prop: 'bii_name' },
      { label: '物料', prop: 'bii_key' }
    ]
  },
  data: {
    type: Object,
    required: true,
    default: () => {
      return {
        bii_name: '物料0000000000000000000000000000000000000000000000',
        bii_key: '000324'
      }
    }
  },
  labelAlign: {
    type: String,
    default: 'right'
  },
  disabled:{
    type: Boolean,
    default:false
  }
})

const form = ref({ ...props.data })

const emit = defineEmits(['delete'])
const onDelete = function(){
  emit('delete')
}
</script>

<template>
  <div class="item-warp">
    <div class="item-deletion" v-if="!disabled">
      <slot/>
    </div>
   <div class="item-container">
     <div class="item-context">
       <ol class="item-rows">
         <li class="item" v-for="col in props.columns">
           <span :class="['label text',`label-align-${props.labelAlign}`]">{{ col.label }}：</span>
           <span class="value text-elipse text" v-if="!col.slot">{{ form[col.prop] }}</span>
           <slot :name="col.prop" :row="form" v-else></slot>
         </li>
       </ol>
     </div>
     <div class="item-oper">
       <div class="item-oper-context">
         <slot name="menu"/>
       </div>
     </div>
   </div>

    <div class="item-deletion" v-if="!disabled">
      <a class="deletion-btn" @click="onDelete">
        <i class="" />
        删除
      </a>
    </div>
  </div>
</template>

<style scoped lang="scss">

.item-warp {
  margin: 12rpx 22rpx;
  display: flex;
  flex-wrap: wrap;

  .item-container{
    flex-grow: 1;
    background-color: #ffff;
    box-shadow: rgba(0, 0, 0, 0.1) 0px 3px 6px;
    border: 1px solid #E5E5E5;
    border-radius: 4px;
    .item-oper{
      padding: 8rpx 12rpx;
      .item-oper-context{
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;
      }

    }
  }

  .item-context {
    border-bottom: 1px solid #E5E5E5;
    flex-grow: 1;
    padding: 8px 12px;
    min-height: 150rpx;
    background-color: #ffff;


    .item-rows {
      list-style-type: none;
      padding: 0;
      margin: 0;


      .item {
        display: flex;
        flex-direction: row;
        align-items: center;

        .text {
          font-size: 14px;
        }

        .label {
          color: #666666;
        }
      }

    }
  }

  .item-deletion {
    display: flex;
    align-items: center;
    justify-content: center;

    .deletion-btn {
      padding: 32rpx 20rpx;
      color: #e63e35;
    }

  }

  .label-align {
    &-left {
      min-width: 80px;
      text-align: left;
    }

    &-right {
      min-width: 80px;
      text-align: right;
    }
  }

  .text-elipse {
    max-width: 230px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
  }

}
</style>
